
//
//  LMNavigationController.m
//  李明微博
//
//  Created by 张青花 on 15/12/4.
//  Copyright (c) 2015年 李明. All rights reserved.
//

#import "LMNavigationController.h"
#import "UIBarButtonItem+Item.h"
@interface LMNavigationController ()<UINavigationControllerDelegate>


@property (nonatomic,strong) id popDelegate;
@end

@implementation LMNavigationController


+ (void)initialize
{
    UIBarButtonItem *item = [UIBarButtonItem appearanceWhenContainedIn:self, nil];
    
    NSMutableDictionary *titleArr = [NSMutableDictionary dictionary];
    
    titleArr[NSForegroundColorAttributeName]=[UIColor orangeColor];
    [item setTitleTextAttributes:titleArr forState:UIControlStateNormal];
}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
    
    [super pushViewController:viewController animated:animated];
    
    
    if (self.viewControllers.count!=0) {
        
    
    
    viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem barButtonItemWithImage:[UIImage imageNamed:@"navigationbar_back"] highImage:[UIImage imageNamed:@"navigationbar_back_highlighted"] target:self action:@selector(leftToTop) forControlEvents:UIControlEventTouchUpInside];
    
    viewController.navigationItem.rightBarButtonItem = [UIBarButtonItem barButtonItemWithImage:[UIImage imageNamed:@"navigationbar_more"] highImage:[UIImage imageNamed:@"navigationbar_more_highlighted"] target:self action:@selector(rightToRoot) forControlEvents:UIControlEventTouchUpInside];
    
        }
}


- (void)leftToTop
{
    [self popViewControllerAnimated:YES];
}

- (void)rightToRoot
{
    [self popToRootViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    _popDelegate = self.interactivePopGestureRecognizer.delegate;
    
    
    self.delegate = self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark 跳转完成的时候调用

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (viewController ==self.viewControllers[0]) {
        
        self.interactivePopGestureRecognizer.delegate =_popDelegate;
    }else
    {
       self.interactivePopGestureRecognizer.delegate = nil;
    }
}


- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    UIWindow *keyWindow = LMKeyWindow;
    
    UITabBarController *tabBarVC = (UITabBarController *)keyWindow.rootViewController;
    
    for (UIView *tabBarButton in tabBarVC.tabBar.subviews) {
        
        if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            [tabBarButton removeFromSuperview];
        }
    }

    
}
@end
